package logic

import (
	"context"
	"doctor-medicine-system/medrpc/medrpc"

	"doctor-medicine-system/api/internal/svc"
	"doctor-medicine-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMedUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedUpdateLogic {
	return &MedUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MedUpdateLogic) MedUpdate(req *types.MedUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	date, err := l.svcCtx.MedRpc.MedUpDate(l.ctx, &medrpc.MedUpDateRequest{
		MedId:   req.MedId,
		MedName: req.MedName,
		MedSize: req.MedSize,
		MedFrom: req.MedFrom,
	})
	if err != nil {
		return &types.Response{
			Message: "修改失败",
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "修改成功",
		Code:    200,
		Data:    date,
	}, nil
}
